<template>
	<div class="">	
	    
		<el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="loginContainer">
		  <h3 class="loginTitle">超市进销存管理登录</h3>
		  <el-form-item label="姓名" prop="wname" >
			<el-input v-model="ruleForm.wname"></el-input>
		  </el-form-item>
		  <el-form-item label="密码" prop="wpassword" >
			<el-input v-model="ruleForm.wpassword"></el-input>
		  </el-form-item>
		 
		 
		  <el-form-item>
			<el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
			<el-button @click="resetForm('ruleForm')">重置</el-button>
		  </el-form-item>
		</el-form>
		
	</div>	
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          wname: '',
          wpassword: ''
        },
        rules: {
          wname: [
            { required: true, message: '请输入姓名', trigger: 'blur' },
          ],
          wpassword: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
		const _this=this
        this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.get('http://localhost:8181/worker/findWorker/'+this.ruleForm.wname+'/'+this.ruleForm.wpassword).then(function(resp){
				console.log(resp)
				if(_this.ruleForm.wname=="admin" && _this.ruleForm.wpassword=="admin"){
					alert('管理员登录成功')
					// _this.$router.push('/Manage')
					_this.$router.push({
						path:'/Manage',
						query:{
							wname:_this.ruleForm.wname
						}
					})
				}
				else if(resp.data == 'sucess'){
					alert('用户登录成功')
		
					_this.$router.push({
						path:'/Manage2',
						query:{
							wname:_this.ruleForm.wname
						}
					})
				}
				else{
					alert('用户名或密码错误,  请重新输入！！！')
					// window.location.reload()
					_this.$router.push('/Login')
				}
			})
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style>
	body{
		background-repeat: no-repeat;
		background-size: cover;
		background-attachment: fixed;
		background-image: url(../assets/hh.jpg);
	}
  .loginContainer{
    border-radius: 15px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 15px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
  .loginTitle{
    margin: 4px auto 20px auto;
    text-align: center;
  }
</style>


